/******************** (C) COPYRIGHT 2004 STMicroelectronics ********************
* File Name          : common.h
* Author             : MCD Application Team
* Date First Issued  : 10/25/2004
* Description        : This file provides all the header of the common functions
********************************************************************************
* History:
*  10/25/2004 : Created
*  11/24/2004 : IAP Version 1.0
********************************************************************************
THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A 
RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR 
CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH 
SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN
IN CONNECTION WITH THEIR PRODUCTS.
********************************************************************************/
#ifndef __common_h
#define __common_h

#include "raw_api.h"
#include "stdio.h"
#include "string.h"
#include "ymodem.h"

//common routines
#define IS_AF(c)	((c >= 'A') && (c <= 'F'))
#define IS_af(c)	((c >= 'a') && (c <= 'f'))
#define IS_09(c)	((c >= '0') && (c <= '9'))
#define ISVALIDHEX(c)	IS_AF(c) || IS_af(c) || IS_09(c)
#define ISVALIDDEC(c)	IS_09(c)
#define CONVERTDEC(c)	(c - '0')

#define CONVERTHEX_alpha(c)	(IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10))	
#define CONVERTHEX(c)   (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c))

// Constants used by Serial Command Line Mode
#define CMD_STRING_SIZE     128

/*******************************************************************************
* Function Name  : Int2Str
* Description    : Convert an Integer to a srting 
* Input 1        : The string
* Input 2        : The intger to be converted  
* Return         : None                                         
*******************************************************************************/
void Int2Str(RAW_U8* str,RAW_U32 intnum);
/*******************************************************************************
* Function Name  : Str2Int
* Description    : Convert a srting to an integer 
* Input 1        : The string to be converted
* Input 2        : The intger value  
* Return         : 1 -- Correct
                 : 0 -- Error                                           
*******************************************************************************/
RAW_U32 Str2Int(RAW_U8 *inputstr,RAW_U32 *intnum);

/*******************************************************************************
* Function Name  : GetIntegerInput
* Description    : Get an integer from the HyperTerminal 
* Input          : The inetger
* Return         : 1 -- Correct
                 : 0 -- Error                                           
*******************************************************************************/
RAW_U32 GetIntegerInput(RAW_U32 * num);

/*******************************************************************************
* Function Name  : GetKey
* Description    : Get a key from the HyperTerminal 
* Input          : None
* Return         : The Key Pressed                                            
*******************************************************************************/
RAW_U8 GetKey(void);

/*******************************************************************************
* Function Name  : GetInputString	
* Description    : Get Input string from the HyperTerminal 
* Input          : The input string
* Return         : None                                          
*******************************************************************************/
void GetInputString (RAW_U8 * buffP);

/*******************************************************************************
* Function Name  : Main_Menu	
* Description    : Display the  Main Menu on to HyperTerminal
* Input          : None
* Return         : None                                          
*******************************************************************************/
void Main_Menu(void );

/*******************************************************************************
* Function Name  : SerialDownload
* Description    : Download a file via serial port 
* Input          : None 
* Return         : None                                                               
*******************************************************************************/
void SerialDownload(void);

#endif
/*******************(C)COPYRIGHT 2004 STMicroelectronics *****END OF FILE****/

